package com.oocl.admin_platform.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.codec.binary.Base64;

import com.oocl.admin_platform.pojo.Merchant;
import com.sun.xml.bind.v2.runtime.output.Encoded;

public class Base64Unit {
	
	/**
	 * base64编码
	 * @param data
	 * @return
	 */
	public static byte[] encode(byte[] data){
		
		byte[] result = Base64.encodeBase64(data);
		
		return result;
		
	}
	
	/**
	 * base64解码
	 * @param data
	 * @return
	 * @throws IOException
	 */
	public static byte[] decode(String data) throws IOException{
		byte[] result = Base64.decodeBase64(data.getBytes());
		return result;
	}
	
//	public static void main(String[] args) throws IOException {
//		InputStream in = new FileInputStream("c:\\1.png");
//		byte[] bb = new byte[in.available()];
//		byte[] b = new byte[in.available()*4];
//		in.read(bb);
//		b = encode(bb);
//		
//		
//		OutputStream out = new FileOutputStream("c:\\2.png");
//		out.write(decode(new String(b)));
//		out.flush();
//		out.close();
//		in.close();
//	}
	
}
